package com.ruoyi.business.controller;

import com.ruoyi.business.domain.Person;
import com.ruoyi.business.service.IPersonService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 人员信息Controller
 * 
 * @author qiancheng
 * @date 2025-06-13
 */
@Api(tags = "人员信息管理")
@RestController
@RequestMapping("/business/person")
public class PersonController extends BaseController
{
    @Autowired
    private IPersonService personService;

    /**
     * 安全管理->>人员管理->>查询人员信息列表
     */
    @ApiOperation("查询人员信息列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("人员信息查询条件") Person person)
    {
        startPage();
        List<Person> list = personService.selectPersonList(person);
        return getDataTable(list);
    }

    /**
     * 导出人员信息列表
     */
    @ApiOperation("导出人员信息列表")
    @PreAuthorize("@ss.hasPermi('business:person:export')")
    @Log(title = "人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ApiParam("人员信息查询条件") Person person)
    {
        List<Person> list = personService.selectPersonList(person);
        ExcelUtil<Person> util = new ExcelUtil<Person>(Person.class);
        util.exportExcel(response, list, "人员信息数据");
    }

    /**
     * 获取人员信息详细信息
     */
    @ApiOperation("获取人员信息详细信息")
    @PreAuthorize("@ss.hasPermi('business:person:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam("人员ID") @PathVariable("id") Long id)
    {
        return success(personService.selectPersonById(id));
    }

    /**
     * 安全管理->>人员管理->>新增人员信息
     */
    @ApiOperation("新增人员信息")
    @Anonymous
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@ApiParam("人员信息") @RequestBody Person person)
    {
        return toAjax(personService.insertPerson(person));
    }

    /**
     * 安全管理->>人员管理->>修改人员信息
     */
    @ApiOperation("修改人员信息")
    @Anonymous
    @PutMapping
    public AjaxResult edit(@ApiParam("人员信息") @RequestBody Person person)
    {
        return toAjax(personService.updatePerson(person));
    }

    /**
     * 安全管理->>人员管理->>删除人员信息
     */
    @ApiOperation("删除人员信息")
    @Anonymous
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("人员ID数组") @PathVariable Long[] ids)
    {
        return toAjax(personService.deletePersonByIds(ids));
    }
}
